package com.liuxinlong.jobs;

import com.liuxinlong.modules.dao.UserDao;
import com.liuxinlong.modules.entity.User;
import com.liuxinlong.utils.RedisUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 使用quartz框架
 */
@Service
@Component("checkUserStatusTask")

public class CheckUserStatusTask {

    @Autowired
    private UserDao userDao;

    @Autowired
    private RedisUtils redisUtils;

    /**
     * 业务逻辑
     */
    public void reptilian(){

        List<User> userList = userDao.getOnlineUserList();
        for (User user: userList) {
            String userKey = user.getId();
            String token = redisUtils.getUserCache(userKey);
            if (StringUtils.isEmpty(token) || StringUtils.isEmpty(token.trim())) {
//                redisUtils.deleteUserCache(userKey);
                userDao.updateUserStatus(userKey,0,null);
            }
        }

    }
}

